﻿using ERP_RORZE_DLL.Product.Base;
using System;
using ERP_RORZE_SYSTEM;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ERP_RORZE_DLL.Product.database;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Product.DAO
{
    public class ClsPartDataDAO : ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();
        //Lấy PartID
        public DataTable GetAllPartID()
        {
            string sql = clsConstantsFuction.ClsFuctionPart.GetAll;

            return Execute.DoStoreProcedure(sql, true);
        }
        // lấy MaterialID
        public DataTable MaterialID()
        {
            string sql = clsConstantsFuction.ClsFuctionMaterial.GetAllMaterialID;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Lấy GetAllMaterial
        public DataTable GetAllMaterial()
        {
            string sql = clsConstantsFuction.ClsFuctionMaterial.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        //Lấy GetAllPartMaterial
        public DataTable GetAllPartMaterial()
        {
            string sql = clsConstantsFuction.ClsFuctionPartData.GetAllPartMaterial;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Lấy GetAllMachineID
        public DataTable GetAllMachineID()
        {
            string sql = clsConstantsFuction.ClsFuctionMachine.GetAllMachine;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Lấy GetAllOptionID
        public DataTable GetAllOptionID()
        {
            string sql = clsConstantsFuction.ClsFuctionOption.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Lấy GetAllJigID
        public DataTable GetAllJigID()
        {
            string sql = clsConstantsFuction.ClsFuctionJig.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Lấy GetAllStaffID
        public DataTable GetAllStaffID()
        {
            string sql = clsConstantsFuction.ClsFuctionStaff.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Lấy OptionData
        public DataTable GetAllOptionData()
        {
            string sql = clsConstantsFuction.ClsFuctionOptionData.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        //Lấy PartData
        public DataTable GetAllPartData()
        {
            string sql = clsConstantsFuction.ClsFuctionPartData.DeleteMaterial;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void DeleteMaterial(ClsPartDataTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPartDataSP.ID, SqlDbType.Int, b.ID),
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionPartData.DeleteMaterial, parameter, true);
        }
        public void InsertPartMaterial(ClsPartDataTable b)
        {

            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Bafu, SqlDbType.Bit, b.Bafu),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.BAnod, SqlDbType.Bit, b.BAnod),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Blast30, SqlDbType.Bit, b.Blast30),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Blast60, SqlDbType.Bit, b.Blast60),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Caciras, SqlDbType.Bit, b.Caciras),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Cleanwave, SqlDbType.Bit, b.Cleanwave),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Cut, SqlDbType.Bit, b.Cut),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.HairLine, SqlDbType.Bit, b.HairLine),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.HandFinish, SqlDbType.Bit, b.HandFinish),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Helisert, SqlDbType.Bit, b.Helisert),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.InputDate, SqlDbType.DateTime, b.InputDate),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Inside, SqlDbType.Bit, b.Inside),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.lenght, SqlDbType.Float, b.Lenght),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.MaterialID, SqlDbType.NVarChar, b.MaterialID),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.MaterialType, SqlDbType.NVarChar, b.MaterialType),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Memo, SqlDbType.NVarChar, b.Memo),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Migaki, SqlDbType.Bit, b.Migaki),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Note, SqlDbType.NVarChar, b.Note),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Otherpro, SqlDbType.NVarChar, b.Otherpro),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.PalCoat, SqlDbType.Bit, b.PalCoat),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.PartID, SqlDbType.NVarChar, b.PartID),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Price, SqlDbType.Int, b.Price),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.RawMachine, SqlDbType.Bit, b.RawMachine),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Seal, SqlDbType.Bit, b.Seal),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.SerialNo, SqlDbType.Bit, b.SerialNo),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.shape, SqlDbType.NVarChar, b.Shape),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Thickness, SqlDbType.Float, b.Thickness),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.VacPac, SqlDbType.Bit, b.VacPac),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.WAnod, SqlDbType.Bit, b.WAnod),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Workpiecesize, SqlDbType.NVarChar, b.Workpiecesize),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.width, SqlDbType.Float, b.Width)
                    
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionPartData.InsertMaterial, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdatePartMaterial(ClsPartDataTable b)
        {

            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPartDataSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Bafu, SqlDbType.Bit, b.Bafu),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.BAnod, SqlDbType.Bit, b.BAnod),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Blast30, SqlDbType.Bit, b.Blast30),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Blast60, SqlDbType.Bit, b.Blast60),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Caciras, SqlDbType.Bit, b.Caciras),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Cleanwave, SqlDbType.Bit, b.Cleanwave),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Cut, SqlDbType.Bit, b.Cut),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.HairLine, SqlDbType.Bit, b.HairLine),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.HandFinish, SqlDbType.Bit, b.HandFinish),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Helisert, SqlDbType.Bit, b.Helisert),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.InputDate, SqlDbType.DateTime, b.InputDate),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Inside, SqlDbType.Bit, b.Inside),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.lenght, SqlDbType.Float, b.Lenght),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.MaterialID, SqlDbType.NVarChar, b.MaterialID),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.MaterialType, SqlDbType.NVarChar, b.MaterialType),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Memo, SqlDbType.NVarChar, b.Memo),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Migaki, SqlDbType.Bit, b.Migaki),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Note, SqlDbType.NVarChar, b.Note),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Otherpro, SqlDbType.NVarChar, b.Otherpro),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.PalCoat, SqlDbType.Bit, b.PalCoat),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.PartID, SqlDbType.NVarChar, b.PartID),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Price, SqlDbType.NVarChar, b.Price),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.RawMachine, SqlDbType.Bit, b.RawMachine),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Seal, SqlDbType.Bit, b.Seal),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.SerialNo, SqlDbType.Bit, b.SerialNo),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.shape, SqlDbType.NVarChar, b.Shape),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Thickness, SqlDbType.Float, b.Thickness),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.VacPac, SqlDbType.Bit, b.VacPac),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.WAnod, SqlDbType.Bit, b.WAnod),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.Workpiecesize, SqlDbType.NVarChar, b.Workpiecesize),
                    CreateParameter(clsConstantsSP.ClsPartDataSP.width, SqlDbType.Float, b.Width)
                    
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionPartData.UpdateMaterial, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void InsertOptionData(ClsOptionDataTable b)
        {

            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.AondNote, SqlDbType.NVarChar, b.AondNote),
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.ClampTime, SqlDbType.Float, b.ClampTime),
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.CLUpdateday, SqlDbType.DateTime, b.CLUpdateday),
                     CreateParameter(clsConstantsSP.ClsOptionDataSP.InputDate, SqlDbType.DateTime, b.InputDate),
                      CreateParameter(clsConstantsSP.ClsOptionDataSP.JigID, SqlDbType.NVarChar, b.JigID),
                       CreateParameter(clsConstantsSP.ClsOptionDataSP.LastOption, SqlDbType.Bit, b.LastOption),
                        CreateParameter(clsConstantsSP.ClsOptionDataSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                         CreateParameter(clsConstantsSP.ClsOptionDataSP.Memo, SqlDbType.NVarChar, b.Memo),
                          CreateParameter(clsConstantsSP.ClsOptionDataSP.Note, SqlDbType.NVarChar, b.Note),
                           CreateParameter(clsConstantsSP.ClsOptionDataSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                            CreateParameter(clsConstantsSP.ClsOptionDataSP.PartID, SqlDbType.NVarChar, b.PartID),
                             CreateParameter(clsConstantsSP.ClsOptionDataSP.ProTime, SqlDbType.Float, b.ProTime),
                              CreateParameter(clsConstantsSP.ClsOptionDataSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                               CreateParameter(clsConstantsSP.ClsOptionDataSP.TechDate, SqlDbType.Bit, b.TechDate),
                                CreateParameter(clsConstantsSP.ClsOptionDataSP.ToolQty, SqlDbType.Int, b.ToolQty),
                                CreateParameter(clsConstantsSP.ClsOptionDataSP.Jig, SqlDbType.Bit, b.Jig),
                                CreateParameter(clsConstantsSP.ClsOptionDataSP.JigType, SqlDbType.NVarChar, b.JigType),
                                 CreateParameter(clsConstantsSP.ClsOptionDataSP.UpdateDay, SqlDbType.DateTime, b.UpdateDay)
                    
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionOptionData.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdateOptionData(ClsOptionDataTable b)
        {

            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.ID, SqlDbType.Int, b.ID),
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.AondNote, SqlDbType.NVarChar, b.AondNote),
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.ClampTime, SqlDbType.Float, b.ClampTime),
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.CLUpdateday, SqlDbType.DateTime, b.CLUpdateday),
                     CreateParameter(clsConstantsSP.ClsOptionDataSP.InputDate, SqlDbType.DateTime, b.InputDate),
                      CreateParameter(clsConstantsSP.ClsOptionDataSP.JigID, SqlDbType.NVarChar, b.JigID),
                       CreateParameter(clsConstantsSP.ClsOptionDataSP.LastOption, SqlDbType.Bit, b.LastOption),
                        CreateParameter(clsConstantsSP.ClsOptionDataSP.MachineID, SqlDbType.NVarChar, b.MachineID),
                         CreateParameter(clsConstantsSP.ClsOptionDataSP.Memo, SqlDbType.NVarChar, b.Memo),
                          CreateParameter(clsConstantsSP.ClsOptionDataSP.Note, SqlDbType.NVarChar, b.Note),
                           CreateParameter(clsConstantsSP.ClsOptionDataSP.OptionID, SqlDbType.NVarChar, b.OptionID),
                            CreateParameter(clsConstantsSP.ClsOptionDataSP.PartID, SqlDbType.NVarChar, b.PartID),
                             CreateParameter(clsConstantsSP.ClsOptionDataSP.ProTime, SqlDbType.Float, b.ProTime),
                              CreateParameter(clsConstantsSP.ClsOptionDataSP.StaffID, SqlDbType.NVarChar, b.StaffID),
                               CreateParameter(clsConstantsSP.ClsOptionDataSP.TechDate, SqlDbType.Bit, b.TechDate),
                                CreateParameter(clsConstantsSP.ClsOptionDataSP.ToolQty, SqlDbType.Int, b.ToolQty),
                                CreateParameter(clsConstantsSP.ClsOptionDataSP.Jig, SqlDbType.Bit, b.Jig),
                                CreateParameter(clsConstantsSP.ClsOptionDataSP.JigType, SqlDbType.NVarChar, b.JigType),
                                 CreateParameter(clsConstantsSP.ClsOptionDataSP.UpdateDay, SqlDbType.DateTime, b.UpdateDay)
                    
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionOptionData.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeleteOptionData(ClsOptionDataTable b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsOptionDataSP.ID, SqlDbType.Int, b.ID),
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionOptionData.Delete, parameter, true);
        }
        //Part List
        public void DeletePart(clsPart b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPastSP.PartID, SqlDbType.NVarChar, b.PartID),
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionPart.Delete, parameter, true);
        }

        public void InsertPart(clsPart b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPastSP.PartID, SqlDbType.NVarChar, b.PartID),
                    CreateParameter(clsConstantsSP.ClsPastSP.CustomerID, SqlDbType.NVarChar, b.customerID),
                    CreateParameter(clsConstantsSP.ClsPastSP.PartName, SqlDbType.NVarChar, b.partName),
                    CreateParameter(clsConstantsSP.ClsPastSP.SupplierID, SqlDbType.NVarChar, b.supplierID),
                    CreateParameter(clsConstantsSP.ClsPastSP.UpQty, SqlDbType.Int, b.upQty)
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionPart.Insert, parameter, true);
        }

        public void UpdatePart(clsPart b)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPastSP.PartID, SqlDbType.NVarChar, b.PartID),
                    CreateParameter(clsConstantsSP.ClsPastSP.CustomerID, SqlDbType.NVarChar, b.customerID),
                    CreateParameter(clsConstantsSP.ClsPastSP.PartName, SqlDbType.NVarChar, b.partName),
                    CreateParameter(clsConstantsSP.ClsPastSP.SupplierID, SqlDbType.NVarChar, b.supplierID),
                    CreateParameter(clsConstantsSP.ClsPastSP.UpQty, SqlDbType.Int, b.upQty)
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionPart.Update, parameter, true);
        }

        //Material
        public void DeleteMaterial(string MaterialID)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMaterialSP.MaterialID, SqlDbType.NVarChar, MaterialID),
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionMaterial.Delete, parameter, true);
        }

        public void InsertMaterial(string MaterialID, string Density, string Type, string UnitPrice)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMaterialSP.MaterialID, SqlDbType.NVarChar, MaterialID),
                    CreateParameter(clsConstantsSP.ClsMaterialSP.Density, SqlDbType.Float, Density),
                    CreateParameter(clsConstantsSP.ClsMaterialSP.Type, SqlDbType.NVarChar, Type),
                    CreateParameter(clsConstantsSP.ClsMaterialSP.UnitPrice, SqlDbType.Money, UnitPrice)
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionMaterial.Insert, parameter, true);
        }

        public void UpdateMaterial(string MaterialID, string Density, string Type, string UnitPrice)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMaterialSP.MaterialID, SqlDbType.NVarChar, MaterialID),
                    CreateParameter(clsConstantsSP.ClsMaterialSP.Density, SqlDbType.Float, Density),
                    CreateParameter(clsConstantsSP.ClsMaterialSP.Type, SqlDbType.NVarChar, Type),
                    CreateParameter(clsConstantsSP.ClsMaterialSP.UnitPrice, SqlDbType.Money, UnitPrice)
                };
            Execute.DoDelete(clsConstantsFuction.ClsFuctionMaterial.Update, parameter, true);
        }

    }
}
